<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>对象 - 构造函数</title>
</head>
<body>

</body>
<script>
    // 构造函数内部原理
    // 1. 在函数体最前面隐式的加上 this = {}
    // 2. 执行this.xxx = xxx;
    // 3. 隐式的返回this
    //
    // 不能返回原始值

    function Student(name, age, sex) {
        // var this = {
        //  name : "",
        //  age : "",
        //  ...
        // }
        this.name = name;
        this.age = sex;
        this.sex = sex;
        this.grade = 2019;

        // return this;

        // return 123; 原始值
    }

    var student = new Student('李四', 18, 'male');


    // 模拟构造函数
    function Person(name, height) {
        var that = {};
        that.name = name;
        that.height = height;
        return that;
    }

    var person = Person('张三', 21);

</script>
</html>
